package com.link.base.base.contract.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.link.core.basic.annotations.JsonParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.link.base.base.contract.model.Contract;
import com.link.base.base.contract.service.ContractService;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 合同
 *
 * @author 阳晓琳
 * @date 2020-09-16 17:25:08
 */
@Controller
@RequestMapping("/link/contract")
public class ContractController extends BasicController<Contract> {

    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private ContractService contractService;

    @Override
    public BasicService<Contract> getBasicService() throws Exception {
        return contractService;
    }

    /**
     * 定点合同复制按钮
     * @param entity
     * @param session
     * @param request
     * @return
     */
    @RequestMapping(value = "/copyPointContract", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> copyPointContract(@JsonParam Contract entity , HttpSession session, HttpServletRequest request) {
        Map<String,Object> result = new HashMap<>(4);
        try {
            Contract contract = contractService.copyPointContract(entity);
            result.put("success",true);
            //将新合同返回
            result.put("newRow",contract);
        } catch (Exception e) {
            result.put("success",false);
            result.put("result",e.getMessage());
        }
        return result;
    }



    /**
     * 框架定点合同失效
     * @author 王昊
     * @param entity
     * @param session
     * @param request
     * @return
     */
    @RequestMapping(value = "/unactive",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> unactiveContract(@JsonParam Contract entity, HttpSession session, HttpServletRequest request) {
        Map<String,Object> result = new HashMap<>(4);
        try {
            contractService.unactiveContract(entity);
            result.put("newRow",entity);
            result.put("success",true);
        } catch (Exception e) {
            result.put("success",false);
            result.put("result",e.getMessage());
        }
        return result;
    }

    /**
     * 框架定点合同审批
     * @author 王昊
     * @param entity
     * @param session
     * @param request
     * @return
     */
    @RequestMapping(value = "/frameContractSubmit" , method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> frameContractSubmit(@JsonParam Contract entity, HttpSession session, HttpServletRequest request) {
        Map<String,Object> result = new HashMap<>(4);
        try {
            contractService.frameContractSubmit(entity);
            result.put("newRow",entity);
            result.put("success",true);
        } catch (Exception e) {
            result.put("success",false);
            result.put("result", e.getMessage());
        }
        return result;
    }


}